package com.kylin.androidlearn1.acticity;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;

import com.kylin.androidlearn1.R;
import com.kylin.androidlearn1.acticity.adapter.ListViewAdapter;
import com.kylin.androidlearn1.acticity.bean.MyEntity;

import java.util.ArrayList;

/**
 * Created by kylinhuang on 10/3/16.
 */
public class DemoActivity extends Activity {
    private ListView mListView;
    private ListViewAdapter mListViewAdapter;
    private Context mContext;

    public void onClick(View v){

        //TODO Activity 跳转
        Intent intent =  new Intent(); //创建意图
        intent.setClass(this,Demo1Activity.class);  //intent 中设置 做什么  跳转的Activity
        startActivity(intent); //intent 告诉系统
        finish();



//        AlertDialog.Builder build = new AlertDialog.Builder(DemoActivity.this);
//        build.setTitle("title");
//        build.setMessage("message");
//
//        AlertDialog mDialog = build.create();
//        mDialog.show();

    }

    private static final String TAG = "DemoActivity";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_demo);

        mContext =  this;

        ArrayList <MyEntity> list =  getData();

        mListView = (ListView)findViewById(R.id.listView);

        mListViewAdapter = new ListViewAdapter(mContext,list); //创建适配器
        mListView.setAdapter(mListViewAdapter);  //ListView 设置 adapter
        mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                MusicPlayAtcicity.actionStart(mContext);
            }
        });


        Log.e(TAG,"onCreate");
    }

    private  ArrayList <MyEntity>  getData() {
        ArrayList<MyEntity> list = new ArrayList<MyEntity>();
        list.add(new MyEntity("小黄","男","1343i4ou4246"));
        list.add(new MyEntity("小利","男","1343i4ou4246"));

        list.add(new MyEntity("小红","男","1343i4ou4246"));
        list.add(new MyEntity("小黄","男","1343i4ou4246"));

        return list;
    }

    @Override
    protected void onStart() {
        super.onStart();
        Log.e(TAG,"onStart");
    }

    @Override
    protected void onPause() {
        super.onPause();
        Log.e(TAG,"onPause");
    }

    @Override
    protected void onResume() {
        super.onResume();
        Log.e(TAG,"onResume");
    }

    @Override
    protected void onStop() {
        super.onStop();
        Log.e(TAG,"onStop");
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        Log.e(TAG,"onDestroy");
    }
}
